﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace StoredProcedureGenerator
{
    /// <summary>
    /// 
    /// </summary>
    public static class StringHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="templateFile"></param>
        /// <param name="replaceInTemplate"></param>
        /// <returns></returns>
        public static string ReplaceString(string templateFile, Dictionary<string, string> replaceInTemplate)
        {
            string newFileContent = "";

            if (!File.Exists(templateFile))
            {
                throw new Exception("Nem letezo file");
            }
            StreamReader sr = File.OpenText(templateFile);

            string oldFileContent = sr.ReadToEnd();
            newFileContent = oldFileContent;

            foreach (KeyValuePair<string, string> kvp in replaceInTemplate)
            {
                newFileContent = newFileContent.Replace("<%" + kvp.Key + "%>", kvp.Value);
            }

            return newFileContent;

        }


    }
}
